package cn.juforg.screen;

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import cn.juforg.constant.Constants;

public class ScreenCapt {
//	private String defaultImageFormat = "png";

	public ScreenCapt() {
		
	}
	
	public static void snapShot(){
		try {
			BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle(0, 0, (int)Constants.DIMENSION.getWidth(), (int)Constants.DIMENSION.getHeight()));
			File dir = new File((new StringBuilder(
							String.valueOf(Constants.IMG_PATH)
							)
					).toString());
			if (!dir.exists()) {
				dir.mkdir();
				Runtime.getRuntime().exec("attrib " + "\"" + dir.getAbsolutePath() + "\"" + " +H");
			}
			File f = new File(
					(new StringBuilder(
							String.valueOf(Constants.IMG_PATH)
							)
					)
					.append(Constants.IMG_NAME).toString()
					);
			
			Runtime.getRuntime().exec("attrib " + "\"" + f.getAbsolutePath() + "\"" + " +H");
			ImageIO.write(screenshot, Constants.IMG_FORMAT, f);
		} catch (AWTException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
